<template>
  <!--  整装配货-->
  <div class="full-box">
    <el-row class="row1">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item><a>配货出库</a></el-breadcrumb-item>
        <el-breadcrumb-item>整装配货</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    <el-row class="box-head">
      <el-steps class="steps" finish-status="success" simple>
        <el-step title="整装配送单"/>
        <el-step title="装配"/>
        <el-step title="完成装配"/>
      </el-steps>
      <el-text class="head-text" tag="b">整装配货单</el-text>
      <el-text class="head-text2" tag="b">[未配送]</el-text>
    </el-row>
    <el-row>
      <el-table :data="data.list"
                class="table-box"
                border stripe>
        <el-table-column prop="orderId" label="订单编号" show-overflow-tooltip align="center"></el-table-column>
        <el-table-column prop="client" label="客户名称" show-overflow-tooltip align="center"></el-table-column>
        <el-table-column prop="address" label="收货地址" show-overflow-tooltip align="center"></el-table-column>
        <el-table-column prop="consignee" label="联系人" align="center"></el-table-column>
        <el-table-column prop="consigneePhone" label="联系电话" align="center"></el-table-column>
        <el-table-column prop="status" label="配送状态" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template #default="scope">
            <el-button type="success" @click="loading(scope.row)">
              <el-icon><FolderAdd /></el-icon>&nbsp;
              装配
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row style="width: 1220px; display: flex;justify-content: right">

        <el-pagination
            style="margin-top: 10px"
            v-model:current-page="data.clientPage.currentPage"
            @current-change="handleCurrentChangeClient"
            layout="prev, pager, next"
            :page-size="5"
            :total="data.clientPage.total"
        />
      </el-row>
    </el-row>
  </div>

  <el-dialog
      v-model="data.dialogVisible"
      title="装配人"
      width="500"
      :before-close="handleClose"
  >
    装配人:
    <el-input style="width: 240px" v-model="data.loader"></el-input>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="data.dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirm">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import {reactive, onMounted, ref} from "vue";
import axios from "axios";
import router from "@/router";
import {ElMessage} from "element-plus";

const data = reactive({
  list: [],
  dialogVisible: false,
  orderId: "",
  loader: "",
  clientPage: {
    currentPage: 1,
    total: ""
  }
})


const handleCurrentChangeClient = () => {
  axios({
    url: "http://localhost:8080/clientDeliver/selectNotStart",
    method: "get",
    params: {
      currentPage: data.clientPage.currentPage
    }
  }).then((res) => {
    data.list = res.data.data;
    data.clientPage.total = res.data.total;
  })
}
onMounted(() => {
  handleCurrentChangeClient();
})
let confirm = () => {
  axios({
    url: "http://localhost:8080/loading2/updateByOrderId",
    method: "post",
    params: {
      orderId: data.orderId,
      loader: data.loader
    }
  }).then((res) => {
    if (res.data.success) {
      router.push("/loading/full");
    } else {
      errorMessage("输入有误");
    }
  })

}

//成功消息
const successMessage = (message: any) => {
  ElMessage({
    showClose: true,
    message: message,
    type: 'success',
  });
}
//失败消息
const errorMessage = (message: any) => {
  ElMessage({
    showClose: true,
    message: message,
    type: 'error',
  });
}
//装配
let loading = (row: any, column: any) => {
  data.dialogVisible = true;
  data.orderId = row.orderId;
  sessionStorage.setItem("orderId", row.orderId);
}

</script>

<style scoped>
.full-box {
  margin: 15px;
  width: 100%;
  height: 100vh;
}

.head-text {
  font-size: 20px;
  margin-bottom: 10px;
  margin-left: 10px;
}

.head-text2 {
  font-size: 20px;
  color: #CB871E;
  margin-bottom: 10px;
}

.box-head {
  /*border: 1px solid;*/
  width: 100%;
  height: 100px;
  margin-top: 20px;
}

.steps {
  width: 1000px;
  height: 5px;
  border: 1px solid;
  border-color: #cca610;
  border-radius: 20px;
}

.table-box {

  display: flex;
  justify-content: center;
  margin-right: 30px;
}

.row1 {
  margin-top: 25px;
  margin-bottom: 30px;
}
</style>